home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / text / misc / port / oldstuff / portsource.lha / Port124.S < prev    next >
Encoding:
Text File  |  1993-02-21  |  15.5 KB  |  1,175 lines

  1. testmode    =    1
  2.  
  3.     include    "src:shadowlord.i"
  4.  
  5. ; V1.01
  6. ; Added bigger understanding of PC box characters.
  7. ; Now also understands one-wide box chars, and thick corner changed to #,
  8. ; single corner to +.
  9.  
  10. ; V1.02
  11. ; Added bad mode error, and error on no space between mode and the rest.
  12.  
  13. ; V1.10
  14. ; Cut endspace.
  15. ; Text output.
  16.  
  17. ; V1.13
  18. ; Percentage & size change
  19. ; extra lf
  20. ; extra cr removal in topc mode
  21.  
  22. ; V1.16
  23. ; Faster translate routines  25% speedup in frompc
  24. ; 6 more in frompc
  25. ; New helptext.
  26.  
  27. ; V1.18  11-feb
  28. ; Upper and lower case modes.
  29.  
  30. ; V1.22  19-feb
  31. ; tabs to spaces
  32. ; 3 new pc box chars
  33. ; bug fixed that confused port if the end of the commandline had spaces.
  34. ; spaces to tabs
  35.  
  36. ; V1.24  21-feb
  37. ; size reduced by 48
  38. ; bug fixed where tabconversion wasn't turned on in spacestotabs
  39. ; causing some strange behavior.
  40. ; reduced code size by making routines use same parts of code.
  41. ; Logic check for options
  42. ; 20% when quiet
  43.  
  44. * 21-Feb-93
  45. * 18 days of hard coding
  46.  
  47. ; during the program
  48. ; a0=source
  49. ; a1=dest
  50. ; a2=spacebuf
  51.  
  52. ; d0=current char
  53. ; d1=load counter
  54. ; d2=savebyte counter
  55.  
  56.  
  57.     if    testmode=1
  58.     lea    test_comline,a0
  59.     move.l    #test_len,d0
  60.     endc
  61.  
  62. progstart:
  63.     clr.b    -1(a0,d0.l)
  64.     move.l    a0,commandstart
  65.     move.w    d0,commandlen
  66.     add.l    d0,a0
  67.     subq.l    #1,a0
  68.     move.l    a0,commandend
  69.  
  70.     lea    dosname,a1
  71.     moveq    #0,d0
  72.     move.l    execbase,a6
  73.     jsr    openlibrary(a6)
  74.     move.l    d0,dosbase
  75.  
  76.     move.l    dosbase,a6
  77.     jsr    output(a6)
  78.     move.l    d0,outstruct
  79.  
  80.     if    testmode=1
  81.     bne    err_testmode
  82.     endc
  83.  
  84.     move.l    #text_cursoroff,d2
  85.     moveq    #5,d3
  86.     bsr    printtext
  87.  
  88.     move.l    commandstart,a0
  89.     tst.b    (a0)            ; if blank commandline, instructions
  90.     beq    helptext
  91.     cmp.b    #"?",(a0)
  92.     beq    helptext
  93.  
  94. parsestart:
  95.     cmp.b    #"-",(a0)
  96.     beq    checkoption
  97.  
  98. parse:
  99.     cmp.b    #" ",1(a0)        ; at least one space after option
  100.     bne    err_nocomlinespace
  101.     cmp.b    #"p",(a0)
  102.     beq    frompcmode
  103.     cmp.b    #"P",(a0)
  104.     beq    topcmode
  105.     cmp.b    #"s",(a0)
  106.     beq    fromsf7mode
  107.     cmp.b    #"S",(a0)
  108.     beq    tosf7mode
  109.     cmp.b    #"u",(a0)
  110.     beq    toupcasemode
  111.     cmp.b    #"l",(a0)
  112.     beq    tolowcasemode
  113.     bra    err_badmode
  114.  
  115. checkoption:
  116.     cmp.b    #"n",1(a0)
  117.     beq    opt_nocutspace
  118.     cmp.b    #"?",1(a0)
  119.     beq    credits
  120.     cmp.b    #"t",1(a0)
  121.     beq    opt_tabconv
  122.     cmp.b    #"s",1(a0)
  123.     beq    opt_spaceconv
  124.     cmp.b    #"q",1(a0)
  125.     beq    opt_quietmode
  126.     bra    err_badcomline
  127.  
  128. opt_nocutspace:
  129.     move.b    #1,mode_nocutspace
  130.     addq.l    #2,a0
  131.     cmp.b    #" ",(a0)
  132.     bne    err_badcomline
  133.     bsr    skipspace
  134.     cmp.l    #0,a0
  135.     beq    err_badcomline
  136.     bra    parsestart
  137.  
  138. opt_tabconv:
  139.     tst.b    tabsize
  140.     bne    err_badlogic
  141.     move.b    2(a0),d0
  142.     cmp.b    #" ",d0
  143.     beq    opt_tabconv1
  144.     sub.b    #"0",d0
  145.     cmp.b    #9,d0
  146.     bhi    err_badcomline
  147.     cmp.b    #1,d0
  148.     bcs    err_badcomline
  149.     bra    opt_bothconv
  150.  
  151. opt_tabconv1:
  152.     move.b    #8,d0
  153.     subq.l    #1,a0
  154.     bra    opt_bothconv
  155.  
  156. opt_spaceconv:
  157.     tst.b    tabsize
  158.     bne    err_badlogic
  159.     move.b    2(a0),d0
  160.     cmp.b    #" ",d0
  161.     beq    opt_spaceconv1
  162.     sub.b    #"0",d0
  163.     cmp.b    #9,d0
  164.     bhi    err_badcomline
  165.     cmp.b    #1,d0
  166.     bcs    err_badcomline
  167.     move.b    d0,spacesize
  168.     bra    opt_bothconv
  169.  
  170. opt_spaceconv1:
  171.     move.b    #8,d0
  172.     move.b    d0,spacesize
  173.     subq.l    #1,a0
  174.  
  175. opt_bothconv:
  176.     move.b    d0,tabsize
  177.     addq.l    #3,a0
  178.     cmp.b    #" ",(a0)
  179.     bne    err_badcomline
  180.     bsr    skipspace
  181.     cmp.l    #0,a0
  182.     beq    err_badcomline
  183.     bra    parsestart
  184.  
  185. opt_quietmode:
  186.     move.b    #1,mode_quiet
  187.     addq.l    #2,a0
  188.     cmp.b    #" ",(a0)
  189.     bne    err_badcomline
  190.     bsr    skipspace
  191.     cmp.l    #0,a0
  192.     beq    err_badcomline
  193.     bra    parsestart
  194.  
  195. frompcmode:
  196.     move.b    #1,mode
  197.     bra    nameparse
  198.  
  199. fromsf7mode:
  200.     move.b    #2,mode
  201.     bra    nameparse
  202.  
  203. tosf7mode:
  204.     move.b    #-2,mode
  205.     bra    nameparse
  206.  
  207. topcmode:
  208.     move.b    #-1,mode
  209.     bra    nameparse
  210.  
  211. toupcasemode:
  212.     move.b    #3,mode
  213.     bra    nameparse
  214.     
  215. tolowcasemode:
  216.     move.b    #4,mode
  217.     bra    nameparse
  218.  
  219. nameparse:
  220.     addq.l    #1,a0
  221.     bsr    skipspace
  222.     cmp.l    #0,a0
  223.     beq    err_badcomline
  224.     move.l    a0,sourcenamestart
  225.     bsr    findend
  226.     cmp.l    #0,a0
  227.     beq    err_badcomline
  228.     move.l    a0,sourcenameend
  229.     addq.l    #1,a0
  230.     sub.l    sourcenamestart,a0
  231.     move.l    a0,sourcenamelen
  232.  
  233.     move.l    sourcenamestart,a0
  234.     move.l    #sourcename,a1
  235.     move.l    sourcenamelen,d0
  236.     subq.l    #1,d0
  237.     bsr    removequotes
  238.  
  239. copysourcename:
  240.     move.b    (a0)+,(a1)+
  241.     dbf    d0,copysourcename
  242.     clr.b    (a1)
  243.  
  244.     move.l    sourcenameend,a0
  245.     addq.l    #1,a0
  246.     cmp.l    commandend,a0
  247.     beq    nodest
  248.  
  249.     bsr    skipspace
  250.     cmp.l    #0,a0
  251.     beq    nodest
  252.     move.l    a0,destnamestart
  253.     bsr    findend
  254.     cmp.l    #0,a0
  255.     beq    err_badcomline
  256.     move.l    a0,destnameend
  257.     addq.l    #1,a0
  258.     sub.l    destnamestart,a0
  259.     move.l    a0,destnamelen
  260.     move.l    a0,d0
  261.  
  262.     move.l    destnamestart,a0
  263.     move.l    #destname,a1
  264.     subq.l    #1,d0
  265.     bsr    removequotes
  266.  
  267. copydestname:
  268.     move.b    (a0)+,(a1)+
  269.     dbf    d0,copydestname
  270.     bra    openfiles
  271.  
  272. removequotes:
  273.     cmp.b    #'"',(a0)
  274.     beq    removequotes1
  275.     rts
  276.  
  277. removequotes1:
  278.     addq.l    #1,a0
  279.     subq.l    #2,d0
  280.     rts
  281.  
  282. nodest:
  283.     move.l    #destname,a1
  284.     move.l    sourcenamestart,a0
  285.     move.l    sourcenamelen,d0
  286.     subq.l    #1,d0
  287.     bsr    removequotes
  288.  
  289. copydestname1:
  290.     move.b    (a0)+,(a1)+
  291.     dbf    d0,copydestname1
  292.  
  293.     cmp.b    #-1,mode
  294.     beq    pcsuffix
  295.     cmp.b    #-2,mode
  296.     beq    sf7suffix
  297.  
  298. amigasuffix:
  299.     lea    text_amigasuf,a0
  300.     moveq    #4-1,d0
  301.  
  302. amigasuffix1:
  303.     move.b    (a0)+,(a1)+
  304.     dbf    d0,amigasuffix1
  305.     bra    openfiles
  306.  
  307. pcsuffix:
  308.     lea    text_pcsuf,a0
  309.     moveq    #3-1,d0
  310.  
  311. pcsuffix1:
  312.     move.b    (a0)+,(a1)+
  313.     dbf    d0,pcsuffix1
  314.     bra    openfiles
  315.  
  316. sf7suffix:
  317.     lea    text_sf7suf,a0
  318.     moveq    #4-1,d0
  319.  
  320. sf7suffix1:
  321.     move.b    (a0)+,(a1)+
  322.     dbf    d0,sf7suffix1
  323.  
  324. openfiles:
  325.     clr.b    (a1)            ; end of filename
  326.     move.l    #sourcename,d1
  327.     move.l    #1005,d2
  328.     move.l    dosbase,a6
  329.     jsr    open(a6)
  330.     tst.l    d0
  331.     beq    err_nosource
  332.     move.l    d0,sourcehandle
  333.  
  334.     move.l    #destname,d1
  335.     move.l    #1006,d2
  336.     move.l    dosbase,a6
  337.     jsr    open(a6)
  338.     tst.l    d0
  339.     beq    err_nodest
  340.     move.l    d0,desthandle
  341.  
  342. readblock:
  343.     move.l    sourcehandle,d1
  344.     move.l    #sourcebuf,d2
  345.     move.l    #1024,d3
  346.     move.l    dosbase,a6
  347.     jsr    read(a6)
  348.     add.l    d0,readbytes
  349.     move.l    d0,d1
  350.     beq    closefiles        ; readbytes=0 - quit
  351.     subq.l    #1,d1
  352.     moveq    #0,d2
  353.  
  354.     lea    sourcebuf,a0
  355.     lea    destbuf,a1
  356.  
  357. morecharacters:
  358.     move.b    (a0)+,d0
  359.     bra    cutspace
  360.  
  361. checknormal:
  362.     cmp.b    #-2,mode
  363.     beq    tosf7
  364.     cmp.b    #-1,mode
  365.     beq    topc
  366.     cmp.b    #2,mode
  367.     beq    fromsf7
  368.     cmp.b    #3,mode
  369.     beq    toupcase
  370.     cmp.b    #4,mode
  371.     beq    tolowcase
  372.  
  373. frompc:
  374.     cmp.b    #" ",d0
  375.     bcs    frompc1
  376.     cmp.b    #"~",d0
  377.     bhi    frompc1
  378.     bra    nextchar
  379.  
  380. frompc1:
  381.     cmp.b    #$84,d0
  382.     beq    ami_lowae
  383.     cmp.b    #$94,d0
  384.     beq    ami_lowoe
  385.     cmp.b    #$8e,d0
  386.     beq    ami_upae
  387.     cmp.b    #$99,d0
  388.     beq    ami_upoe
  389.     cmp.b    #13,d0
  390.     beq    nochar
  391.     cmp.b    #0,d0
  392.     beq    nochar
  393.     cmp.b    #$1a,d0            ; ctrl+z
  394.     beq    nochar
  395.     cmp.b    #$c9,d0
  396.     beq    ami_bigcorner
  397.     cmp.b    #$bb,d0
  398.     beq    ami_bigcorner
  399.     cmp.b    #$c8,d0
  400.     beq    ami_bigcorner
  401.     cmp.b    #$bc,d0
  402.     beq    ami_bigcorner
  403.     cmp.b    #$cd,d0
  404.     beq    ami_doubleline
  405.     cmp.b    #$ba,d0
  406.     beq    ami_upline
  407.     cmp.b    #$b3,d0
  408.     beq    ami_upline
  409.     cmp.b    #$b0,d0
  410.     beq    ami_box
  411.     cmp.b    #$b1,d0
  412.     beq    ami_box
  413.     cmp.b    #$b2,d0
  414.     beq    ami_box
  415.     cmp.b    #$c4,d0
  416.     beq    ami_singleline
  417.     cmp.b    #$c0,d0
  418.     beq    ami_smallcorner
  419.     cmp.b    #$d9,d0
  420.     beq    ami_smallcorner
  421.     cmp.b    #$bf,d0
  422.     beq    ami_smallcorner
  423.     cmp.b    #$da,d0
  424.     beq    ami_smallcorner
  425.     cmp.b    #$d4,d0
  426.     beq    ami_bigcorner
  427.     cmp.b    #$c3,d0
  428.     beq    ami_smallcorner
  429.     cmp.b    #$b7,d0
  430.     beq    ami_smallcorner
  431.     cmp.b    #$b6,d0
  432.     beq    ami_bigcorner
  433.     cmp.b    #$d3,d0
  434.     beq    ami_smallcorner
  435.     cmp.b    #$d6,d0
  436.     beq    ami_smallcorner
  437.     cmp.b    #$bd,d0
  438.     beq    ami_smallcorner
  439.     cmp.b    #20,d0
  440.     beq    ami_182
  441.     cmp.b    #128,d0
  442.     beq    ami_231
  443.  
  444. nextchar:
  445.     move.b    d0,(a1)+
  446.     addq.l    #1,d2
  447.     addq.w    #1,col
  448.  
  449. nochar:
  450.     dbf    d1,morecharacters
  451.  
  452.     move.l    desthandle,d1
  453.     move.l    d2,d3
  454.     add.l    d2,writtenbytes
  455.     move.l    #destbuf,d2
  456.     move.l    dosbase,a6
  457.     jsr    write(a6)
  458.  
  459.     cmp.b    #1,mode_quiet
  460.     beq    readblock
  461.  
  462.     move.l    #text_input,d2
  463.     moveq    #15,d3
  464.     bsr    printtext
  465.  
  466.     lea    numberbuf,a0
  467.     move.l    readbytes,d0
  468.     bsr    num2ascii
  469.  
  470.     move.l    a0,d2
  471.     move.l    d0,d3
  472.     bsr    printtext
  473.  
  474.     move.l    #text_output,d2
  475.     moveq    #18,d3
  476.     bsr    printtext
  477.  
  478.     lea    numberbuf,a0
  479.     move.l    writtenbytes,d0
  480.     bsr    num2ascii
  481.  
  482.     move.l    a0,d2
  483.     move.l    d0,d3
  484.     bsr    printtext
  485.  
  486.     move.l    #text_cr,d2
  487.     moveq    #1,d3
  488.     bsr    printtext
  489.  
  490.     bra    readblock
  491.  
  492. cutspace:
  493.     move.l    spacepointer,a2
  494.     cmp.b    #" ",d0
  495.     beq    addspace
  496.     cmp.b    #9,d0            ; tab
  497.     beq    addtab
  498.  
  499.     tst.b    mode_nocutspace
  500.     bne    cutspace2
  501.  
  502.     cmp.b    #10,d0            ; lf
  503.     beq    cutspaces
  504.     cmp.b    #13,d0            ; cr
  505.     beq    cutspaces
  506.  
  507. cutspace1:
  508.     tst.l    tabs
  509.     bne    linkspaces
  510.  
  511. cutspace3:
  512.     tst.l    spacenumber
  513.     bne    linkspaces2
  514.     bra    checknormal
  515.  
  516. cutspace2:
  517.     cmp.b    #10,d0
  518.     beq    clearcol
  519.     cmp.b    #13,d0
  520.     beq    clearcol
  521.     bra    cutspace1
  522.  
  523. clearcol:
  524.     move.w    #-1,col
  525.     bra    cutspace1
  526.  
  527. addspace:
  528.     addq.l    #1,spacenumber
  529.     move.b    d0,(a2)+
  530.     move.l    a2,spacepointer
  531.     addq.w    #1,col
  532.     bra    checkconvspace
  533.  
  534. addtab:
  535.     move.b    tabsize,d4        ; if tabsize is zero, just add it
  536.     bne    tabconv
  537.     bra    addspace
  538.  
  539. tabconv:
  540.     ext.w    d4
  541.     ext.l    d4
  542.     move.w    col,d3
  543.     ext.l    d3
  544.     divu    d4,d3
  545.     swap    d3
  546.     sub.w    d3,d4
  547.     add.l    d4,spacenumber
  548.     add.w    d4,col
  549.     subq.w    #1,d4
  550.     move.b    #" ",d0
  551.  
  552. tabconv1:
  553.     move.b    d0,(a2)+
  554.     dbf    d4,tabconv1
  555.     move.l    a2,spacepointer
  556.  
  557. checkconvspace:
  558.     tst.b    spacesize
  559.     beq    nochar
  560.     cmp.l    #1,spacenumber        ; if spacenumber<1, skip
  561.     bcs    nochar
  562.     move.w    col,d5
  563.     ext.l    d5
  564.     move.l    spacenumber,d3
  565.     move.b    spacesize,d4
  566.     ext.w    d4
  567.     ext.l    d4
  568.  
  569.     divu    d4,d5
  570.     swap    d5
  571.     tst.w    d5
  572.     beq    foundconvspace
  573.     bra    nochar
  574.  
  575. foundconvspace:
  576.     move.l    #spacebuf,spacepointer
  577.     addq.l    #1,tabs
  578.     clr.l    spacenumber
  579.     bra    nochar
  580.  
  581. cutspaces:
  582.     clr.l    spacenumber
  583.     clr.l    tabs
  584.     move.l    #spacebuf,spacepointer
  585.     move.w    #-1,col            ; col will be zero when eol gets added
  586.     bra    checknormal
  587.  
  588. linkspaces:
  589.     move.l    tabs,d3
  590.     clr.l    tabs
  591.     add.l    d3,d2            ; tabs -> bytes to be written
  592.     subq.l    #1,d3
  593.  
  594. linkspaces1:
  595.     move.b    #9,(a1)+
  596.     dbf    d3,linkspaces1
  597.     bra    cutspace3
  598.  
  599. linkspaces2:
  600.     move.l    spacenumber,d3
  601.     add.l    d3,d2            ; spaces -> bytes to be written
  602.     subq.l    #1,d3
  603.     lea    spacebuf,a2
  604.     move.l    a2,spacepointer
  605.  
  606. linkspaces3:
  607.     move.b    (a2)+,(a1)+
  608.     dbf    d3,linkspaces3
  609.     clr.l    spacenumber
  610.     bra    checknormal
  611.  
  612. topc:
  613.     cmp.b    #"ä",d0
  614.     beq    pc_lowae
  615.     cmp.b    #"ö",d0
  616.     beq    pc_lowoe
  617.     cmp.b    #"Ä",d0
  618.     beq    pc_upae
  619.     cmp.b    #"Ö",d0
  620.     beq    pc_upoe
  621.     cmp.b    #13,d0
  622.     beq    nochar
  623.     cmp.b    #10,d0
  624.     beq    addcr
  625.     cmp.b    #0,d0
  626.     beq    nochar
  627.     cmp.b    #$1a,d0            ; ctrl+z
  628.     beq    nochar
  629.     bra    nextchar
  630.  
  631. fromsf7:
  632.     cmp.b    #"{",d0
  633.     beq    ami_lowae
  634.     cmp.b    #"|",d0
  635.     beq    ami_lowoe
  636.     cmp.b    #"[",d0
  637.     beq    ami_upae
  638.     cmp.b    #"\",d0
  639.     beq    ami_upoe
  640.     cmp.b    #13,d0
  641.     beq    nochar
  642.     cmp.b    #0,d0
  643.     beq    nochar
  644.     cmp.b    #$1a,d0            ; ctrl+z
  645.     beq    nochar
  646.     bra    nextchar
  647.  
  648. tosf7:
  649.     cmp.b    #"ä",d0
  650.     beq    sf7_lowae
  651.     cmp.b    #"ö",d0
  652.     beq    sf7_lowoe
  653.     cmp.b    #"Ä",d0
  654.     beq    sf7_upae
  655.     cmp.b    #"Ö",d0
  656.     beq    sf7_upoe
  657.     cmp.b    #10,d0
  658.     beq    addcr
  659.     cmp.b    #0,d0
  660.     beq    nochar
  661.     cmp.b    #$1a,d0            ; ctrl+z
  662.     beq    nochar
  663.     bra    nextchar
  664.  
  665. toupcase:
  666.     cmp.b    #"ä",d0
  667.     beq    ami_upae
  668.     cmp.b    #"ö",d0
  669.     beq    ami_upoe
  670.     cmp.b    #"a",d0
  671.     bcs    nextchar
  672.     cmp.b    #"z",d0
  673.     bhi    nextchar
  674.  
  675.     eor.b    #%100000,d0
  676.     bra    nextchar
  677.  
  678. tolowcase:
  679.     cmp.b    #"Ä",d0
  680.     beq    ami_lowae
  681.     cmp.b    #"Ö",d0
  682.     beq    ami_lowoe
  683.     cmp.b    #"A",d0
  684.     bcs    nextchar
  685.     cmp.b    #"Z",d0
  686.     bhi    nextchar
  687.  
  688.     or.b    #%100000,d0
  689.     bra    nextchar
  690.  
  691. ami_182:
  692.     move.b    #182,d0
  693.     bra    nextchar
  694.  
  695. ami_231:
  696.     move.b    #231,d0
  697.     bra    nextchar
  698.  
  699. ami_singleline:
  700.     move.b    #"-",d0
  701.     bra    nextchar
  702.  
  703. ami_box:
  704.     move.b    #$7f,d0
  705.     bra    nextchar
  706.  
  707. ami_upline:
  708.     move.b    #"|",d0
  709.     bra    nextchar
  710.  
  711. ami_doubleline:
  712.     move.b    #"=",d0
  713.     bra    nextchar
  714.  
  715. ami_smallcorner:
  716.     move.b    #"+",d0
  717.     bra    nextchar
  718.  
  719. ami_bigcorner:
  720.     move.b    #"#",d0
  721.     bra    nextchar
  722.  
  723. ami_lowae:
  724.     move.b    #"ä",d0
  725.     bra    nextchar
  726.  
  727. ami_lowoe:
  728.     move.b    #"ö",d0
  729.     bra    nextchar
  730.  
  731. ami_upae:
  732.     move.b    #"Ä",d0
  733.     bra    nextchar
  734.  
  735. ami_upoe:
  736.     move.b    #"Ö",d0
  737.     bra    nextchar
  738.  
  739. pc_lowae:
  740.     move.b    #$84,d0
  741.     bra    nextchar
  742.  
  743. pc_lowoe:
  744.     move.b    #$94,d0
  745.     bra    nextchar
  746.  
  747. pc_upae:
  748.     move.b    #$8e,d0
  749.     bra    nextchar
  750.  
  751. pc_upoe:
  752.     move.b    #$99,d0
  753.     bra    nextchar
  754.  
  755. sf7_lowae:
  756.     move.b    #"{",d0
  757.     bra    nextchar
  758.  
  759. sf7_lowoe:
  760.     move.b    #"|",d0
  761.     bra    nextchar
  762.  
  763. sf7_upae:
  764.     move.b    #"[",d0
  765.     bra    nextchar
  766.  
  767. sf7_upoe:
  768.     move.b    #"\",d0
  769.     bra    nextchar
  770.  
  771. addcr:
  772.     move.b    #13,(a1)+
  773.     addq.l    #1,d2
  774.     bra    nextchar
  775.  
  776. closefiles:
  777.     move.l    sourcehandle,d1
  778.     move.l    dosbase,a6
  779.     jsr    close(a6)
  780.     move.l    desthandle,d1
  781.     move.l    dosbase,a6
  782.     jsr    close(a6)
  783.  
  784.     move.l    #text_final,d2
  785.     moveq    #26,d3
  786.     bsr    printtext
  787.  
  788.     move.l    readbytes,d1
  789.     move.l    writtenbytes,d0
  790.  
  791.     sub.l    d1,d0
  792.     bmi    closefiles1        ; negative
  793.  
  794.     move.l    d0,d7
  795.     beq    closefiles2        ; if zero, no sign
  796.  
  797.     move.l    #text_possign,d2
  798.     moveq    #1,d3
  799.     bsr    printtext
  800.     bra    closefiles2
  801.  
  802. closefiles1:
  803.     neg.l    d0
  804.     move.l    d0,d7
  805.  
  806.     move.l    #text_negsign,d2
  807.     moveq    #1,d3
  808.     bsr    printtext
  809.  
  810. closefiles2:
  811.     move.l    d7,d0
  812.     lea    numberbuf,a0
  813.     bsr    num2ascii
  814.  
  815.     move.l    a0,d2
  816.     move.l    d0,d3
  817.     bsr    printtext
  818.  
  819.     move.l    #text_doublespace,d2
  820.     moveq    #2,d3
  821.     bsr    printtext
  822.  
  823.     move.l    writtenbytes,d0
  824.     move.l    readbytes,d1
  825.     bsr    percentage
  826.  
  827.     lea    numberbuf,a0
  828.     bsr    num2ascii
  829.  
  830.     move.l    a0,d2
  831.     move.l    d0,d3
  832.     bsr    printtext
  833.  
  834.     move.l    #text_percentsign,d2
  835.     move.l    #11,d3
  836.     bsr    printtext
  837.  
  838.     move.l    #text_lf,d2
  839.     move.l    #1,d3
  840.     bsr    printtext
  841.     bra    endprogram1
  842.  
  843. helptext:
  844.     move.l    #text_helptext,d2
  845.     move.l    #len_helptext,d3
  846.     bsr    printtext
  847.     bra    endprogram1
  848.  
  849. credits:
  850.     move.l    #text_credits,d2
  851.     move.l    #len_credits,d3
  852.     bsr    printtext
  853.     bra    endprogram1
  854.  
  855.     if    testmode=1
  856. err_testmode:
  857.     move.l    #$ffff,d0
  858.  
  859. err_testmode1:
  860.     move.w    #$f00,$dff180
  861.     dbf    d0,err_testmode1
  862.     bra    endprogram1
  863.     endc
  864.  
  865. err_nosource:
  866.     move.l    #text_nosource,d2
  867.     moveq    #28,d3
  868.     bsr    printerror
  869.     bra    endprogram1
  870.  
  871. err_badcomline:
  872.     move.l    #text_badcomline,d2
  873.     moveq    #17,d3
  874.     bsr    printerror
  875.     bra    endprogram1
  876.  
  877. err_nodest:
  878.     move.l    #text_nodest,d2
  879.     moveq    #33,d3
  880.     bsr    printerror
  881.     bra    endprogram2
  882.  
  883. err_badmode:
  884.     move.l    #text_badmode,d2
  885.     moveq    #24,d3
  886.     bsr    printerror
  887.     bra    endprogram1
  888.  
  889. err_nocomlinespace:
  890.     move.l    #text_nocomlinespace,d2
  891.     moveq    #52,d3
  892.     bsr    printerror
  893.     bra    endprogram1
  894.  
  895. err_badlogic:
  896.     move.l    #text_badlogic,d2
  897.     moveq    #25,d3
  898.     bsr    printerror
  899.     bra    endprogram1
  900.  
  901. endprogram1:
  902.     move.l    #text_cursoron,d2
  903.     moveq    #5,d3
  904.     bsr    printtext
  905.  
  906.     move.l    execbase,a6
  907.     move.l    dosbase,a1
  908.     jsr    closelibrary(a6)
  909.     moveq    #0,d0
  910.     rts
  911.  
  912. endprogram2:
  913.     move.l    sourcehandle,d1
  914.     move.l    dosbase,a6
  915.     jsr    close(a6)
  916.     bra    endprogram1
  917.  
  918. **********
  919. ** SUBS **
  920. **********
  921.  
  922. printerror:
  923.     movem.l    d2/d3,-(a7)
  924.     move.l    #text_error,d2
  925.     move.l    #8,d3
  926.     bsr    printtext
  927.     movem.l    (a7)+,d2/d3
  928.     bsr    printtext
  929.     rts
  930.  
  931. printtext:
  932.     if    testmode=1
  933.     rts
  934.     endc
  935.  
  936.     move.l    outstruct,d1
  937.     move.l    dosbase,a6
  938.     jsr    write(a6)
  939.     rts
  940.  
  941. skipspace:
  942.     cmp.b    #" ",(a0)
  943.     beq    skipspace1
  944.     rts
  945.  
  946. skipspace1:
  947.     addq.l    #1,a0
  948.     cmp.l    commandend,a0
  949.     bcs    skipspace
  950.     move.l    #0,a0
  951.     rts
  952.  
  953. findend:
  954.     cmp.b    #'"',(a0)
  955.     beq    findend_quote
  956.  
  957. findend_space:
  958.     addq.l    #1,a0
  959.     cmp.b    #" ",(a0)
  960.     beq    findend_space1
  961.     cmp.b    #0,(a0)
  962.     beq    findend_space1
  963.     cmp.l    commandend,a0
  964.     bls    findend_space
  965.     move.l    #0,a0
  966.     rts
  967.  
  968. findend_space1:
  969.     subq.l    #1,a0
  970.     rts
  971.  
  972. findend_quote:
  973.     addq.l    #1,a0
  974.     cmp.b    #'"',(a0)
  975.     bne    findend_quote1
  976.     rts
  977.  
  978. findend_quote1:
  979.     cmp.l    commandend,a0
  980.     bls    findend_quote
  981.     move.l    #0,a0
  982.     rts
  983.  
  984.     include    "src:Num2ASCII-2.S"
  985.     include    "src:Percentage.S"
  986.  
  987. **********
  988. ** DATA **
  989. **********
  990.  
  991.     section    fastdata,data
  992.  
  993. spacepointer:
  994.     dc.l    spacebuf
  995.  
  996. text_helptext:
  997.     incbin    "src:Port/PortOpts1"
  998.  
  999. text_credits:
  1000.     incbin    "src:Port/PortOpts2"
  1001.  
  1002. text_cursoroff:
  1003.     dc.b    27,"[0 p"
  1004.  
  1005. text_cursoron:
  1006.     dc.b    27,"[1 p"
  1007.  
  1008. text_error:
  1009.     dc.b    "ERROR!  "
  1010.  
  1011. text_badcomline:
  1012.     dc.b    "Bad commandline.",10
  1013.  
  1014. text_badsource:
  1015.     dc.b    "Bad sourcefile.",10
  1016.  
  1017. text_nosource:
  1018.     dc.b    "Could not open source file.",10
  1019.  
  1020. text_nodest:
  1021.     dc.b    "Could not open destination file.",10
  1022.  
  1023. text_badmode:
  1024.     dc.b    "Bad mode specification.",10
  1025.  
  1026. text_nocomlinespace:
  1027.     dc.b    "The mode must be separated with at least one space.",10
  1028.  
  1029. text_badlogic:
  1030.     dc.b    "Conflict in commandline.",10
  1031.  
  1032. text_input:
  1033.     dc.b    27,"[1mInput: ",27,"[0m"
  1034.  
  1035. text_output:
  1036.     dc.b    "  ",27,"[1mOutput: ",27,"[0m"
  1037.  
  1038. dosname:
  1039.     dc.b    "dos.library",0
  1040.  
  1041. text_amigasuf:
  1042.     dc.b    ".AMI"
  1043.  
  1044. text_pcsuf:
  1045.     dc.b    ".PC"
  1046.  
  1047. text_sf7suf:
  1048.     dc.b    ".SF7"
  1049.  
  1050. text_cr:
  1051.     dc.b    13
  1052.  
  1053. text_lf:
  1054.     dc.b    10
  1055.  
  1056. text_final:
  1057.     dc.b    27,"[1mFile size change:",27,"[0m "
  1058.  
  1059. text_negsign:
  1060.     dc.b    "-"
  1061.  
  1062. text_possign:
  1063.     dc.b    "+"
  1064.  
  1065. text_percentsign:
  1066.     dc.b    "%        "
  1067.  
  1068. text_doublespace:
  1069.     dc.b    "  "
  1070.  
  1071.     if    testmode=1
  1072.  
  1073. test_comline:
  1074.     dc.b    "-s -t p ram:test",10
  1075.  
  1076. test_comlineend:
  1077.  
  1078. test_len    =    test_comlineend-test_comline
  1079.     endc
  1080.  
  1081.     section    fastblank,bss
  1082.  
  1083. tabs:
  1084.     ds.l    1
  1085.  
  1086. writtenbytes:
  1087.     ds.l    1
  1088.  
  1089. readbytes:
  1090.     ds.l    1
  1091.  
  1092. sourcehandle:
  1093.     ds.l    1
  1094.  
  1095. desthandle:
  1096.     ds.l    1
  1097.  
  1098. outstruct:
  1099.     ds.l    1
  1100.  
  1101. destnamestart:
  1102.     ds.l    1
  1103.  
  1104. destnameend:
  1105.     ds.l    1
  1106.  
  1107. destnamelen:
  1108.     ds.l    1
  1109.  
  1110. sourcenamestart:
  1111.     ds.l    1
  1112.  
  1113. sourcenameend:
  1114.     ds.l    1
  1115.  
  1116. sourcenamelen:
  1117.     ds.l    1
  1118.  
  1119. commandstart:
  1120.     ds.l    1
  1121.  
  1122. commandend:
  1123.     ds.l    1
  1124.  
  1125. commandlen:
  1126.     ds.l    1
  1127.  
  1128. dosbase:
  1129.     ds.l    1
  1130.  
  1131. spacenumber:
  1132.     ds.l    1
  1133.  
  1134. col:
  1135.     ds.w    1
  1136.  
  1137. mode:
  1138.     ds.b    1
  1139.  
  1140. sourcename:
  1141.     ds.b    256
  1142.  
  1143. destname:
  1144.     ds.b    256
  1145.  
  1146. sourcebuf:
  1147.     ds.b    1024
  1148.  
  1149. destbuf:
  1150.     ds.b    2048
  1151.  
  1152. spacebuf:
  1153.     ds.b    1024
  1154.  
  1155. numberbuf:
  1156.     ds.b    10
  1157.  
  1158. tabsize:
  1159.     ds.b    1
  1160.  
  1161. spacesize:
  1162.     ds.b    1
  1163.  
  1164. mode_case:
  1165.     ds.b    1
  1166.  
  1167. mode_nocutspace:
  1168.     ds.b    1
  1169.  
  1170. mode_quiet:
  1171.     ds.b    1
  1172.  
  1173. len_helptext    =    text_credits-text_helptext
  1174. len_credits    =    text_cursoroff-text_credits
  1175.